package com.lims.landInfo.dao;

import javacommon.base.*;
import cn.org.rapid_framework.page.*;

import com.lims.landInfo.model.*;
import com.lims.landInfo.vo.query.*;

import org.springframework.stereotype.Repository;
/**
 * @author zzh
 * @version 1.0
 * @since 1.0
 */
@Repository @SuppressWarnings("unchecked")
public class LandDao extends BaseHibernateDao<Land,java.lang.String>{

	
	public Class getEntityClass() {
		return Land.class;
	}
	
	public Page findPage(LandQuery query) {
        //XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
        // [column]为字符串拼接, {column}为使用占位符. [column]为使用字符串拼接,如username='[username]',偷懒时可以使用字符串拼接 
        // [column] 为PageRequest的属性
		String sql = "select t from Land t where 1=1 "
			  	+ "/~ and t.address = {address} ~/"
			  	+ "/~ and t.area = {area} ~/"
			  	+ "/~ and t.changetype = {changetype} ~/"
				+ "/~ and t.createdate >= {createdateBegin} ~/"
				+ "/~ and t.createdate <= {createdateEnd} ~/"
			  	+ "/~ and t.credentialsarea = {credentialsarea} ~/"
			  	+ "/~ and t.credentialsnumber = {credentialsnumber} ~/"
			  	+ "/~ and t.credentialsstate = {credentialsstate} ~/"
			  	+ "/~ and t.describe = {describe} ~/"
			  	+ "/~ and t.ename = {ename} ~/"
			  	+ "/~ and t.eno = {eno} ~/"
			  	+ "/~ and t.facility = {facility} ~/"
			  	+ "/~ and t.gettype = {gettype} ~/"
			  	+ "/~ and t.improvement = {improvement} ~/"
			  	+ "/~ and t.industrialresearch = {industrialresearch} ~/"
				+ "/~ and t.landdate >= {landdateBegin} ~/"
				+ "/~ and t.landdate <= {landdateEnd} ~/"
			  	+ "/~ and t.landno = {landno} ~/"
			  	+ "/~ and t.oldcontent = {oldcontent} ~/"
			  	+ "/~ and t.oldno = {oldno} ~/"
			  	+ "/~ and t.othertype = {othertype} ~/"
			  	+ "/~ and t.owner = {owner} ~/"
			  	+ "/~ and t.landrange = {landrange} ~/"
			  	+ "/~ and t.reason = {reason} ~/"
			  	+ "/~ and t.securityhousing = {securityhousing} ~/"
			  	+ "/~ and t.sno = {sno} ~/"
			  	+ " order by t.sno asc ";
        
		return pageQuery(sql,query);
	}
	
	/**
	 * 根据单位取信息
	 * @param query
	 * @return
	 */
	public ListRange findLandByCondition(LandQuery query) {
		//String hql = "select ld.landno,ld.ename,ld.address,ld.area,ld.gettype from Land ld";
		String hql = "select ld.landno,ld.ename,ld.address,ld.area,ld.credentialsarea,d.dicValue " +
				"from Land ld,LandDictionary d " +
				"where ld.gettype=d.dicKey and d.colno='getType'";
		Page page = pageQuery(hql, query);
		ListRange range = new ListRange(); 
		range.setTotal(page.getTotalCount());
		range.setRows(page.getResult().toArray());
		return range;
	}
	

}
